function PyResultTj(){
	this.form=this.InitForm();
	this.grid=null;
	this.InitGrid();
	
	this.InitOrg();
	
	
}

PyResultTj.prototype.addresult=function(result,msg){
	if(result>0){
		top.mylayui.msg('操作成功', {icon: 1});
		top.mylayui.closeAll('iframe');
		vPyResultTj.searchlist();
	}
	else{
		if(msg){
			top.mylayui.msg(msg, {icon: 0});
		}else{
			top.mylayui.msg('操作失败', {icon: 0});
		}
	}
}

PyResultTj.prototype.InitOrg = function() {
	var comboboxm=$("#orgid").ligerComboBox({
		valueField : 'orgid',
		textField : 'orgname',
		selectBoxWidth : 250,
		selectBoxHeight:250,
		treeLeafOnly:false,
		valueFieldID:"hid",
		tree: {url : '../common/get_org_list?orgtype=0',
			checkbox: false, 
			nodeWidth:150,
			ajaxType: 'get', 
			idFieldName: 'orgid',
			textFieldName:"orgname",
			idField:"orgid",
        	parentIDField:"orgparentid"
		},
		onSelected : function(orgid, orgname) {// id为空值，name为选择的值
			$("#hidszdw").val(orgid);
			vPyResultTj.searchlist();
		},
		width : 250
	});
	return comboboxm;
}

PyResultTj.prototype.InitForm=function(){
	var form;
    $("#year").val($("#hidyear").val());
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
       form.on('select(year)', function (data) { 

    	   vPyResultTj.searchlist();
       });
       form.on('select(quarter)', function (data) { 
    	    
    	   vPyResultTj.searchlist();
       });
       
	   form.render();
	});  
	return form;
}


PyResultTj.prototype.InitGrid=function (){
	var year=$("#year").val();
	var quarter=$('#quarter').val();
	
	var _this = this;
    window.liger.remove("listorg");
    if (_this.grid == null) {
        _this.grid = $("#listorg").ligerGrid({
            columns: [
                      //{ display: '序号', width: 80, name: 'rowNum' },
                     { display: '机构名称', width:230, align:'left',name: 'orgname',id:"orgname"},
                     { display: '年份', width: 60, name: 'year' },
                     { display: '季度', width: 60, name: 'quarter' },
                     { display: '单位在岗人数', width: 100, name: 'zgrs' },
                     { display: '状态', width: 80, name: 'status', render: function (rowdata, rowindex, value) { 
                    	 if(rowdata.status==1){
                    		 return "提交";
                    	 }
                    	 else if(rowdata.status==2){
                    		 return "归档";
                    	 }
                    	 else if(rowdata.status==3){
                    		 return "驳回";
                    	 }
                     }},
                     { display: '说明', width: 120, name: 'remark' },
                     { display: '参加考核人数', columns:
                         [
                          { display: '小计', name: 'xjcount', align: 'center', width: 50 }, 
                          { display: '好', name: 'haocount', width: 50, align: 'center'},
                          { display: '合格', name: 'hgcount', width: 50, align: 'center' },
                          { display: '差', name: 'chacount', width: 50, align: 'center' },
                          { display: '不定考核结果', name: 'bdjgcount', width: 90, align: 'center' },
                      ] },
                     { display: '未参加考核人数', width: 105, name: 'bcjkhrs' },
                     {display: '操作', width: 100, name: 'userid', render: function (rowdata, rowindex, value) {
                    	var html='';
                    	if(rowdata.status==1){
                    		html+='<img class="btn-img" src="'+ctxStatic+'/images/button/guidang.png" onclick="vPyResultTj.openadd('+rowdata.orgstatustjid+','+rowdata.orgid+','+rowdata.year+','+rowdata.quarter+',2)" alt="归档" title="归档">';
                        	html+='<img class="btn-img" src="'+ctxStatic+'/images/button/bohui.png" onclick="vPyResultTj.openadd('+rowdata.orgstatustjid+','+rowdata.orgid+','+rowdata.year+','+rowdata.quarter+',3)" alt="驳回" title="驳回">';
                    	}
                    	return html;
                        
                     }}
            ],
            pageSize: 30,
            url: "get_list_org_tj" + '?time=' + new Date().getTime(),
            delayLoad: false,            //初始化时是否加载,为true时,不加载,为false时,则加载
            sortName: null,
            dataAction: 'server',
            parms: {
                Method: "",
                year: year,quarter:quarter
                ,orgid:$("#hidszdw").val()
            },
            sortOrder: null,
            sourceObj: _this.grid,
            root: 'items',                       //数据源字段名
            record: 'countRecord',                    //数据源记录数字段名
            pageParmName: 'CurrentPage',               //页索引参数名，(提交给服务器)
            pagesizeParmName: 'PageSize',        //页记录数参数名，(提交给服务器)
            data: {},
            width: "100%",
            height: '100%',
            heightDiff: 0,
            rowHeight:28,
            onSuccess: function (rowdata, rowindex) { if (rowdata.status > 0) { } },
            alternatingRow: true,
            border: 0,
            usePager:false,
            tree:{
            	columnId:"orgname",
            	idField:"orgid",
            	parentIDField:"orgparentid"
            	
            }
        })
    }
}

PyResultTj.prototype.openadd=function(orgstatustjid,orgid,year,quarter,status){
	var title="";
	if(status==2){
		title='归档';
	}
	else if(status==3){
		title='驳回';
	}
	top.mylayui.open({
         type: 2,
         title: title,
         shadeClose: true,
         shade: 0.5,
         area: ['500px', '300px'],
         content: 'pyresult/pyresult_tj_edit?orgstatustjid='+orgstatustjid+'&orgid='+orgid+'&year='+year+"&quarter="+quarter+'&status='+status
       }); 

	var iframeele=top.$(".layui-layer-content").find('iframe');
	iframeele.css({"height":$(iframeele).height()-10});
}

PyResultTj.prototype.searchlist = function () {
	var year=$("#year").val();
	var quarter=$('#quarter').val();
    this.grid.setOptions({
        newPage: 1, parms: {
            Method: "",
            year: year,quarter:quarter
            ,orgid:$("#hidszdw").val()
        }
    });
    this.grid.loadData();
    
}

var vPyResultTj=null;
$(function(){
	vPyResultTj=new PyResultTj();
})
